package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysNovelBook;
import com.ruoyi.system.mapper.SysNovelBookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysNovelCommentMapper;
import com.ruoyi.system.domain.SysNovelComment;
import com.ruoyi.system.service.ISysNovelCommentService;

/**
 * 评论Service业务层处理
 *
 * @author lcn
 * @date 2022-11-14
 */
@Service
public class SysNovelCommentServiceImpl implements ISysNovelCommentService {
    @Autowired
    private SysNovelBookMapper sysNovelBookMapper;

    @Autowired
    private SysNovelCommentMapper sysNovelCommentMapper;

    /**
     * 查询评论
     *
     * @param id 评论主键
     * @return 评论
     */
    @Override
    public SysNovelComment selectSysNovelCommentById(Long id) {
        SysNovelComment sysNovelComment = sysNovelCommentMapper.selectSysNovelCommentById(id);
        sysNovelComment.setBookName(sysNovelBookMapper.selectSysNovelBookById(sysNovelComment.getBookId()).getBookName());
        return sysNovelComment;
    }

    /**
     * 查询评论列表
     *
     * @param sysNovelComment 评论
     * @return 评论
     */
    @Override
    public List<SysNovelComment> selectSysNovelCommentList(SysNovelComment sysNovelComment) {
        List<SysNovelComment> list = sysNovelCommentMapper.selectSysNovelCommentList(sysNovelComment);
        for (SysNovelComment novelComment : list) {
            SysNovelBook book = sysNovelBookMapper.selectSysNovelBookById(novelComment.getBookId());
            if (book != null) {
                novelComment.setBookName(book.getBookName());
            }
        }
        return list;
    }

    /**
     * 新增评论
     *
     * @param sysNovelComment 评论
     * @return 结果
     */
    @Override
    public int insertSysNovelComment(SysNovelComment sysNovelComment) {
        sysNovelComment.setCreateTime(DateUtils.getNowDate());
        return sysNovelCommentMapper.insertSysNovelComment(sysNovelComment);
    }

    /**
     * 修改评论
     *
     * @param sysNovelComment 评论
     * @return 结果
     */
    @Override
    public int updateSysNovelComment(SysNovelComment sysNovelComment) {
        sysNovelComment.setUpdateTime(DateUtils.getNowDate());
        return sysNovelCommentMapper.updateSysNovelComment(sysNovelComment);
    }

    /**
     * 批量删除评论
     *
     * @param ids 需要删除的评论主键
     * @return 结果
     */
    @Override
    public int deleteSysNovelCommentByIds(Long[] ids) {
        return sysNovelCommentMapper.deleteSysNovelCommentByIds(ids);
    }

    /**
     * 删除评论信息
     *
     * @param id 评论主键
     * @return 结果
     */
    @Override
    public int deleteSysNovelCommentById(Long id) {
        return sysNovelCommentMapper.deleteSysNovelCommentById(id);
    }
}
